package org.dizena.utils;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextProvider implements ApplicationContextAware
{
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(@NotNull ApplicationContext ac) throws BeansException
    {
        SpringContextProvider.context = ac;
    }

    public static <T> T getBean(Class<T> requiredType)
    {
        return context.getBean(requiredType);
    }

    public static <T> T getBean(String name, Class<T> requiredType)
    {
        return context.getBean(name, requiredType);
    }

    public static Object getBean(String name)
    {
        return context.getBean(name);
    }

    public static boolean containsBean(String name)
    {
        return context.containsBean(name);
    }

    public static boolean isSingleton(String name)
    {
        return context.isSingleton(name);
    }

    public static Class<?> getType(String name)
    {
        return context.getType(name);
    }
}